package com.zh.work.controller.platform.virtual;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zh.common.entity.JSONResult;
import com.zh.work.dao.platform.virtual.VirtualTwMapper;
import com.zh.work.entity.virtual.VirtualRechargeTrans;
import com.zh.work.entity.virtual.VirtualRechargeTransH;
import com.zh.work.service.platform.virtual.VirtualTwService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * code is far away from bug with the animal protecting
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃代码无BUG！
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 *
 * @Description: 虚拟账户提现控制器
 * @Author: Li.HuiNeng
 * @Create in: 2020-02-19 14:04
 * @Version: 1.0.1
 */
@Api(value = "虚拟账户提现控制器", produces = "application/json", tags = {"虚拟账户提现控制器"})
@RestController
@RequestMapping("/twManage")
public class VirtualTwController {

    @Autowired
    private VirtualTwService service;

    @Autowired
    private VirtualTwMapper mapper;

    @ApiOperation(value = "分页查询提现当天数据集", tags = {"getPagesVirtualWdTrans"}, notes = "分页查询提现当天数据集")
    @GetMapping("/getPagesVirtualWdTrans")
    public JSONResult<List<VirtualRechargeTrans>> getPagesVirtualWdTrans(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageSize") Integer pageSize,
            @ApiParam(value = "账户信息实体类", name = "VirtualRechargeTrans") VirtualRechargeTrans virtualRechargeTrans) {
        JSONResult<List<VirtualRechargeTrans>> jsonResult = new JSONResult<>();
        try {
            IPage<VirtualRechargeTrans> result = this.service.selectVirtualTwTransPages(new Page<>(pageNo, pageSize), virtualRechargeTrans);
            jsonResult.setTotal(result.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }


    @ApiOperation(value = "分页查询提现历史数据集", tags = {"getPagesVirtualWdTrans"}, notes = "分页查询提现历史数据集")
    @GetMapping("/getPagesVirtualWdTransH")
    public JSONResult<List<VirtualRechargeTransH>> getPagesVirtualWdTransH(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageSize") Integer pageSize,
            @ApiParam(value = "账户信息实体类", name = "VirtualRechargeTrans") VirtualRechargeTransH virtualRechargeTransH) {
        JSONResult<List<VirtualRechargeTransH>> jsonResult = new JSONResult<>();
        try {
            IPage<VirtualRechargeTransH> result = this.service.selectVirtualTwTransHPages(new Page<>(pageNo, pageSize), virtualRechargeTransH);
            jsonResult.setTotal(result.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }

    @ApiOperation(value = "提现确认", tags = {"putTransConfirm"}, notes = "提现确认")
    @PostMapping("/putTransConfirm")
    @ResponseBody
    public JSONResult<Object> putTransConfirm(@RequestBody MultipartFile file) {
        JSONResult<Object> jsonResult = new JSONResult<>();
        try {
            Map<String,Object> map = service.putModVirtualTwConfirm(file);
            if ((Boolean) map.get("success")) {
                jsonResult.setMessage(map.get("msg").toString());
                jsonResult.setSuccess(true);
            } else {
                if (map.get("excelErr") != null) {
                    jsonResult.setMessage(map.get("excelErr").toString());
                    jsonResult.setSuccess(false);
                    return jsonResult;
                }
            }
        } catch (Exception e) {
            jsonResult.setCode(e.hashCode());
            jsonResult.setSuccess(false);
            jsonResult.setMessage(e.getLocalizedMessage());
            e.printStackTrace();
        }
        return jsonResult;
    }



    @ApiOperation(value = "分页查询清算当天数据集", tags = {"getTwClearTransPages"}, notes = "分页查询清算当天数据集")
    @GetMapping("/getTwClearTransPages")
    public JSONResult<List<VirtualRechargeTrans>> getTwClearTransPages(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageSize") Integer pageSize,
            @ApiParam(value = "账户信息实体类", name = "VirtualRechargeTrans") VirtualRechargeTrans virtualRechargeTrans) {
        JSONResult<List<VirtualRechargeTrans>> jsonResult = new JSONResult<>();
        try {
            IPage<VirtualRechargeTrans> result = this.service.selectTwClearTransPages(new Page<>(pageNo, pageSize), virtualRechargeTrans);
            jsonResult.setTotal(result.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }


    @ApiOperation(value = "分页查询清算历史数据集", tags = {"getTwClearTransPagesH"}, notes = "分页查询提现历史数据集")
    @GetMapping("/getTwClearTransPagesH")
    public JSONResult<List<VirtualRechargeTransH>> getTwClearTransPagesH(
            @ApiParam(value = "起始页", name = "pageNo") Integer pageNo,
            @ApiParam(value = "当前页显示数量", name = "pageSize") Integer pageSize,
            @ApiParam(value = "账户信息实体类", name = "VirtualRechargeTrans") VirtualRechargeTransH virtualRechargeTransH) {
        JSONResult<List<VirtualRechargeTransH>> jsonResult = new JSONResult<>();
        try {
            IPage<VirtualRechargeTransH> result = this.service.selectTwClearTransHPages(new Page<>(pageNo, pageSize), virtualRechargeTransH);
            jsonResult.setTotal(result.getTotal());
            jsonResult.setData(result.getRecords());
            jsonResult.setMessage("操作成功");
            jsonResult.setSuccess(true);
            jsonResult.setCode(200);
        } catch (Exception e) {
            jsonResult.setMessage(e.getLocalizedMessage());
            jsonResult.setSuccess(false);
            e.printStackTrace();
        }
        return jsonResult;
    }


}
